home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
C for beginners.adf
/
source
/
array.c
< prev
next >
Wrap
C/C++ Source or Header
|
1978-01-17
|
856b
|
41 lines
/* array.c 13 */
#define FALSE 0
#define TRUE 1
#define MAXENTRY 20
long total(); /* Declaration of the function */
void main()
{
int i, number, end = FALSE;
long sum, data[MAXENTRY];
for(i = 0; i <MAXENTRY && !end; i++)
{
printf("Enter %d. value: ", i+1);
scanf("%6ld", &data[i]); /* 6 digits limit */
if(!data[i])
end = TRUE;
}
number = i - end; /* If last entry 0, than one less */
sum = total(data, number);
printf("The Sum of all %d values is %ld\n", number, sum);
printf("Deviation from Average %.9lf:\n", (double) sum / number);
for(i=0; data[i] > 0; i++)
printf("Value %d: %5.9lf%%\n", i+1, data[i] * 100.0 / ( (double) sum / number ) - 100.0);
}
long total(array, cnt)
long array[];
int cnt;
{
long sum = 0;
while(cnt--) /* short and precise */
sum += array[cnt];
return sum;
}